
package View;

import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

/**
 *
 * @author CCD gruppe 2
 */
public class ResourceFrame extends javax.swing.JFrame {

    /** Creates new form ResourceFrame */
    public ResourceFrame() {
        initComponents();
    }

    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JButton newTypeButton;
    private javax.swing.JTextField resourceNameTextField;
    private javax.swing.JComboBox resourceTypeBox;
    private javax.swing.JTextField resourceTypeTextField;
    private javax.swing.JButton saveButton;
    private DefaultComboBoxModel resourceTypeComboModel;
    private javax.swing.JButton closeButton;

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        resourceNameTextField = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        resourceTypeBox = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        saveButton = new javax.swing.JButton();
        newTypeButton = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        resourceTypeTextField = new javax.swing.JTextField();
        resourceTypeComboModel= new DefaultComboBoxModel();
        resourceTypeBox.setModel(resourceTypeComboModel);
        closeButton = new javax.swing.JButton();

        resourceNameTextField.setName("resourceName"); // NOI18N

        jLabel1.setText("Ressursnavn:");

        jLabel2.setText("Type:");


        saveButton.setText("Opprett");

        newTypeButton.setText("Ny Type");

        jLabel4.setText("Type navn:");
        closeButton.setText("Lukk");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1)
                    .add(jLabel2)
                    .add(jLabel3)
                    .add(jLabel4))
                .add(34, 34, 34)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, closeButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 381, Short.MAX_VALUE)
                    .add(newTypeButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 381, Short.MAX_VALUE)
                    .add(saveButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 381, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                        .add(resourceTypeTextField)
                        .add(resourceTypeBox, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(resourceNameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 370, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(resourceNameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel1))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel2)
                    .add(resourceTypeBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jLabel3)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(jLabel4)
                        .add(resourceTypeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(18, 18, 18)
                .add(saveButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(newTypeButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 9, Short.MAX_VALUE)
                .add(closeButton)
                .addContainerGap())
        );
        resourceTypeTextField.setVisible(false);
        pack();
        setCenterPos(this);
    }// </editor-fold>

    private static void setCenterPos(JFrame frame) {
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        int x = (int) ((screen.getWidth() - frame.getWidth()) / 2);
        int y = (int) ((screen.getHeight() - frame.getHeight()) / 2);
        frame.setLocation(x, y);
    }

    /**
     * A method that shows the required elements to add a new type
     */
    public void newTypeButtonPressed(){
        jLabel4.setVisible(true);
        jLabel2.setVisible(false);
        resourceTypeTextField.setVisible(true);
        resourceTypeBox.setVisible(false);
        newTypeButton.setText("Angre");
    }

    /**
     * A method that reverts the required elements to add a new type
     */
    public void regretButtonPressed(){
        jLabel4.setVisible(false);
        jLabel2.setVisible(true);
        resourceTypeTextField.setVisible(false);
        resourceTypeBox.setVisible(true);
        newTypeButton.setText("Ny Type");
    }

    /**
     * A method that clears the input.
     */
    public void clearInput(){
        resourceTypeTextField.setText("");
        resourceNameTextField.setText("");
    }

    public JButton getNewTypeButton() {
        return newTypeButton;
    }

    public void setNewTypeButton(JButton newTypeButton) {
        this.newTypeButton = newTypeButton;
    }

    public JTextField getResourceNameTextField() {
        return resourceNameTextField;
    }

    public void setResourceNameTextField(JTextField resourceNameTextField) {
        this.resourceNameTextField = resourceNameTextField;
    }

    public JComboBox getResourceTypeBox() {
        return resourceTypeBox;
    }

    public void setResourceTypeBox(JComboBox resourceTypeBox) {
        this.resourceTypeBox = resourceTypeBox;
    }

    public JTextField getResourceTypeTextField() {
        return resourceTypeTextField;
    }

    public void setResourceTypeTextField(JTextField resourceTypeTextField) {
        this.resourceTypeTextField = resourceTypeTextField;
    }

    public JButton getSaveButton() {
        return saveButton;
    }

    public void setSaveButton(JButton saveButton) {
        this.saveButton = saveButton;
    }

    public DefaultComboBoxModel getResourceTypeComboModel() {
        return resourceTypeComboModel;
    }

    public void setResourceTypeComboModel(DefaultComboBoxModel resourceTypeComboModel) {
        this.resourceTypeComboModel = resourceTypeComboModel;
    }

    public JLabel getjLabel4() {
        return jLabel4;
    }

    public void setjLabel4(JLabel jLabel4) {
        this.jLabel4 = jLabel4;
    }

    public JButton getCloseButton() {
        return closeButton;
    }

    public void setCloseButton(JButton closeButton) {
        this.closeButton = closeButton;
    }

}
